package com.mooer.app;

import java.util.ArrayList;
import java.util.List;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabWidget;

import com.mooer.R;
import com.mooer.utils.ui.UiUtils;

public class Sign extends TabActivity implements OnClickListener {

	private TabHost tabHost;

	private TabWidget tabWidget;

	private ImageView signNear, signMe, signBusiness;

	private List<View> vs;

	private OnPreDrawListener op;

	private String tab = "business";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.sign);
		Intent intent = getIntent();
		if (intent.getStringExtra("tab") != null) {
			tab = intent.getStringExtra("tab");
		}
		vs = new ArrayList<View>();
		signNear = (ImageView) findViewById(R.id.sign_nearby);
		signMe = (ImageView) findViewById(R.id.sign_me);
		signBusiness = (ImageView) findViewById(R.id.sign_business);
		vs.add(signBusiness);
		vs.add(signMe);
		vs.add(signNear);
		op = UiUtils.initButtonState(signBusiness);
		initTab();
	}

	private void initTab() {
		tabHost = getTabHost();
		Intent layout1intent = new Intent();
		layout1intent.setClass(this, SignNear.class);
		final TabHost.TabSpec layout1spec = tabHost.newTabSpec("near");
		layout1spec.setIndicator("");
		layout1spec.setContent(layout1intent);
		tabHost.addTab(layout1spec);

		Intent layout2intent = new Intent();
		layout2intent.setClass(this, SignMe.class);
		final TabHost.TabSpec layout2spec = tabHost.newTabSpec("me");
		layout2spec.setIndicator("");
		layout2spec.setContent(layout2intent);
		tabHost.addTab(layout2spec);

		Intent layout3intent = new Intent();
		layout3intent.setClass(this, SignBusiness.class);
		final TabHost.TabSpec layout3spec = tabHost.newTabSpec("business");
		layout3spec.setIndicator("");
		layout3spec.setContent(layout3intent);
		tabHost.addTab(layout3spec);

		tabWidget = tabHost.getTabWidget();
		for (int i = 0; i < tabWidget.getChildCount(); i++) {
			View view = tabWidget.getChildAt(i);
			view.setBackgroundColor(0);
		}
		tabHost.setOnTabChangedListener(new OnTabChangeListener() {

			@Override
			public void onTabChanged(String tabId) {
				if ("business".equals(tabId)) {
					UiUtils.buttonStateChange(vs, signBusiness, op);
				} else if ("me".equals(tabId)) {
					UiUtils.buttonStateChange(vs, signMe, op);
				} else if ("near".equals(tabId)) {
					UiUtils.buttonStateChange(vs, signNear, op);
				}

			}
		});
		tabHost.setCurrentTabByTag(tab);

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

	}

}
